<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
    求出最大值与总和
    如果最大值大于总和的一半，则返回 总和 - 最大值 的两倍 + 1
    否则返回总和即可
 */
    var numberOfWeeks = function (milestones) {
      const sum = milestones.reduce((a, b) => a + b)
      let max = Math.max(...milestones)

      if (max > Math.floor(sum / 2)) {
        return (sum - max) * 2 + 1
      }

      return sum
    };
    console.log(numberOfWeeks(milestones = [1, 2, 3]))
  </script>
</body>

</html>